package translinkApp.DialogBoxes.LocationsList;

import java.util.ArrayList;

import translinkApp.Data.ResolvedLocation.ResolvedLocation;
import translinkApp.Data.ResolvedLocation.ResolvedLocationList;

import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;

public class LocationsListDialog extends Builder {
	public ResolvedLocation locationFound;
	
	
	public LocationsListDialog(final Context context, ResolvedLocationList locations,
			final boolean isStreet) {
		this(context, locations, isStreet, "Pick a location");

	}
	
	
	public LocationsListDialog(final Context context, ResolvedLocationList locations,
			final boolean isStreet, String title) {
		super(context);

		ArrayList<CharSequence> displayAddresses = new ArrayList<CharSequence>();
		ArrayList<CharSequence> infoAddresses = new ArrayList<CharSequence>();

		for (ResolvedLocation location : locations) {

			displayAddresses.add(location.getDisplayAddress());
			infoAddresses.add(location.getLocationInformation());
		}

		final CharSequence[] items = displayAddresses.toArray(new CharSequence[0]);
		final CharSequence[] infoList = infoAddresses.toArray(new CharSequence[0]);

		setTitle(title);

		setItems(items, new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int item) {

				String selectedItem = (String) items[item];

				locationFound = new ResolvedLocation(selectedItem, infoList[item].toString(),
						isStreet);

			}
		});

	}
}